import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_business_2003a/pages/index_page.dart';
import 'package:flutter_business_2003a/provider/cart_provider.dart';
import 'package:flutter_business_2003a/provider/child_category_provider.dart';
import 'package:flutter_business_2003a/provider/counter.dart';
import 'package:flutter_business_2003a/provider/current_index_provider.dart';
import 'package:flutter_business_2003a/provider/detail_info_provider.dart';
import 'package:flutter_business_2003a/router/application.dart';
import 'package:flutter_business_2003a/router/router.dart';
import 'package:provider/provider.dart';

///Provider创建过程
///1.创建一个Provider,相当于全局变量
///2.在main方法中注册这个全局变量的类(Provider)
///3.使用方法 Provider.of<Counter>(context,listen:false);注意***需要添加泛型(Counter)才能调用到具体的某一个Provider
///4.调用(读取)Provider中的变量时,不需要添加listen:false,修改变量时需要添加
void main() {
  runApp(MultiProvider(
    providers: [
      ChangeNotifierProvider(create: (_) => Counter()),
      ChangeNotifierProvider(create: (_) => ChildCategoryProvider()),
      ChangeNotifierProvider(create: (_) => DetailInfoProvider()),
      ChangeNotifierProvider(create: (_) => CartProvider()),
      ChangeNotifierProvider(create: (_) => CurrentIndexProvider()),
    ],
    child: const MyApp(),
  ));
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final router = FluroRouter();
    Routers.configureRoutes(router);
    Application.router = router;
    return MaterialApp(
      title: '百姓生活+',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primarySwatch: Colors.pink),
      home: IndexPage(),
      onGenerateRoute: Application.router!.generator,
    );
  }
}
